package com.yang.job.domain.event.handler;


import com.google.common.eventbus.Subscribe;
import com.yang.job.domain.event.SaveJobPostEvent;
import com.yang.job.domain.gateway.repository.IJobModelRepository;
import com.yang.job.domain.model.YangJobModel;
import com.yang.job.infra.event.IEventHandler;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class SaveJobPostEventHandler implements IEventHandler<SaveJobPostEvent> {
    @Resource
    private IJobModelRepository jobModelRepository;

    @Override
    @Subscribe
    public void execute(SaveJobPostEvent event) {
        Integer jobId = event.getData();
        YangJobModel yangJobModel = jobModelRepository.getYangJobModelById(jobId);
        if (yangJobModel == null) {
            return;
        }
        if (!yangJobModel.isOpen()) {
            return;
        }
        // 执行任务
        yangJobModel.submitJob();
    }
}
